import 'package:aone_common/controllers/game_category/game_category_logic.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:prototype/views/game_category/widgets/provider_selector.dart';

import '../game_category_controller.dart';

class GameAppBar extends StatelessWidget with PreferredSizeWidget {
  const GameAppBar({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final state = GameCategoryLogic.to.state;
    final ctrl = GameCategoryController.to;
    return AppBar(
      titleSpacing: 0.0,
      automaticallyImplyLeading: false,
      centerTitle: true,
      title: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          GestureDetector(
            child: Padding(
              padding: EdgeInsets.only(left: 18.0.w),
              child: const Icon(Icons.arrow_back_ios),
            ),
            onTap: Get.back,
          ),
          GestureDetector(
            child: Padding(
              padding: EdgeInsets.only(left: 10.0.w),
              child: const Icon(Icons.favorite_outline_rounded),
            ),
            onTap: ctrl.scaffoldKey.currentState?.openDrawer,
          ),
          Expanded(
            child: Padding(
              padding: EdgeInsets.only(left: 33.0.w),
              child: GestureDetector(
                onTap: ctrl.toggleProviderVisible,
                child: Obx(() {
                  IconData _icon = !ctrl.isProviderVisible
                      ? Icons.keyboard_arrow_up_rounded
                      : Icons.keyboard_arrow_down_rounded;
                  return Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(state.title),
                      Icon(_icon),
                    ],
                  );
                }),
              ),
            ),
          )
        ],
      ),
      actions: [
        Padding(
          padding: EdgeInsets.symmetric(horizontal: 5.0.w),
          child: GestureDetector(
            onTap: () {},
            child: const Icon(Icons.access_time_rounded),
          ),
        ),
        Padding(
          padding: EdgeInsets.symmetric(horizontal: 5.0.w),
          child: GestureDetector(
            onTap: () {},
            child: const Icon(Icons.search),
          ),
        ),
        Padding(
          padding: EdgeInsets.only(left: 5.0, right: 18.0.w),
          child: GestureDetector(
            onTap: ctrl.toggleViewType,
            child: Obx(
              () {
                IconData _icon = ctrl.isGridView
                    ? Icons.format_list_bulleted_rounded
                    : Icons.grid_view;
                return Icon(_icon);
              },
            ),
          ),
        ),
      ],
    );
  }

  @override
  Size get preferredSize => AppBar().preferredSize;
}
